package com.hxzy.shop.commodity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxzy.shop.commodity.mapper.DrugInnerClassifiedManagementMapper;
import com.hxzy.shop.commodity.service.DrugInnerClassifiedManagementService;
import com.hxzy.shop.entity.DrugInnerClassifiedManagement;
import org.springframework.stereotype.Service;

@Service
public class DrugInnerClassifiedManagementServiceImpl extends ServiceImpl<DrugInnerClassifiedManagementMapper, DrugInnerClassifiedManagement> implements DrugInnerClassifiedManagementService {
    @Override
    public boolean addClassified(Long drugUid, Long stairClassifiedId, Long secondLevelClassifiedId) {
        DrugInnerClassifiedManagement management = new DrugInnerClassifiedManagement();
        management.setDrugId(drugUid);
        management.setParentClassifiedManagementId(stairClassifiedId);
        management.setSonClassifiedManagementId(secondLevelClassifiedId);

        return this.save(management);
    }

    @Override
    public boolean updateClassified(Long id, Long stairClassifiedId, Long secondLevelClassifiedId) {
        boolean remove = this.remove(new LambdaQueryWrapper<DrugInnerClassifiedManagement>()
                .eq(DrugInnerClassifiedManagement::getDrugId, id)
        );
        return addClassified(id, stairClassifiedId, secondLevelClassifiedId);
    }
}